package teach.aistar.controller;

import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import teach.aistar.model.entity.*;
import teach.aistar.model.vo.Result;
import teach.aistar.service.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class HomeController {
    @GetMapping("/user/index11")
    public String index11(){
        return "index11";
    }

    @Autowired
    private IBuyCarsService iBuyCarsService;

    @Autowired
    private ICarStyleService iCarStyleService;

    @Autowired
    private ICarBandsService iCarBandsService;

    @PostMapping("/user/addlike")
    @ResponseBody
    public Result add(String id){
        System.out.println("111111111"+id);
       if(id != null){
           int x = iBuyCarsService.update(Integer.valueOf(id));
           System.out.println(x);
       }
        return new Result("200","添加成功",null);
    }

     @Autowired
     private  ITalkService iTalkService;
    @GetMapping("/user/index")
    public String index(HttpServletRequest req){

        //获取pageNow
        String pageNow = req.getParameter("pageNow");
        if(null == pageNow || pageNow.trim().length()==0){
            pageNow = "1";
        }
        PageInfo<CarDetail> pageInfo = iBuyCarsService.findAllBy(Integer.valueOf(pageNow),8);
        List<CarBrands> carBrands = iCarBandsService.selectAll();
        List<CarStyle> carStyles =iCarStyleService.findAll();

        List<Talk> talks =  iTalkService.findAll();

        req.setAttribute("talks",talks);
        req.setAttribute("carBrands",carBrands);
        req.setAttribute("carStyles",carStyles);
        req.setAttribute("pageInfo",pageInfo);
        return "index";
    }

    @GetMapping("/user/car")
    public String sellcar(){
        return "sell-car";
    }

    @GetMapping("/user/carok")
    public String sellcarok(){
        return "sell-carok";
    }

    @GetMapping("/user/personindex")
    public String personindex(){
        return "personindex";
    }

    @GetMapping("/user/admin-info")
    public String admininfo(){
        return "admin-info";
    }

    @GetMapping("/user/article-list")
    public String articlelist(){
        return "article-list";
    }

    @Autowired
    private IOrderService iOrderService;

    @Autowired
    private IOrderDetailsService iOrderDetailsService;

    @Autowired
    private IUserDetailService iUserDetailService;

    @Autowired
    private IInsureService iInsureService;

    @Autowired
    private IExamineService iExamineService;

    //我的订单 - 信息显示
    @GetMapping("/user/danye-list")
    public String add(HttpServletRequest request, HttpSession session) {
        List<Orders> orders=iOrderService.selectOrderAll();
        List<CarBrands> bands = iCarBandsService.selectAll();
        List<OrdersDetails> ordersDetails=iOrderDetailsService.selectDeatilsAll();
        List<CarStyle> styles = iCarStyleService.findAll();
        List<UserDetail> userDetails=iUserDetailService.selectDetailAll();

        request.setAttribute("ordersDetailsList",ordersDetails);
        request.setAttribute("brandsList", bands);
        request.setAttribute("ordersList",orders);
        request.setAttribute("stylesList",styles);
        request.setAttribute("userDetailsList",userDetails);
        return "danye-list";
    }

    //我的订单 - 信息删除
    @GetMapping("/user/deleteOrders")
    @ResponseBody
    public Result deleteSale(String id) {
        iOrderService.deleteById(Integer.valueOf(id));
        iOrderDetailsService.deleteByOrderId(Integer.valueOf(id));
        return new Result("200");
    }


    @GetMapping("/user/deleteSkillOrders")
    @ResponseBody
    public Result deleteSalex(String id) {
        iOrderService.deleteById(Integer.valueOf(id));
        iOrderDetailsService.deleteByOrderId(Integer.valueOf(id));
        return new Result("200");
    }



    //我的保险 - 信息显示
    @GetMapping("/user/annual-list")
    public String insur(HttpServletRequest request, HttpSession session) {
        List<Orders> orders=iOrderService.selectOrderAll();
        List<CarBrands> bands = iCarBandsService.selectAll();
        List<CarStyle> styles = iCarStyleService.findAll();
        List<Insure> insures=iInsureService.selectInsureAll();
        List<UserDetail> userDetails=iUserDetailService.selectDetailAll();
        request.setAttribute("orderList",orders);
        request.setAttribute("brandsList", bands);
        request.setAttribute("stylesList",styles);
        request.setAttribute("insuresList",insures);
        request.setAttribute("userDetailList",userDetails);

        return "annual-list";
    }

    //我的年审 - 信息显示
    @GetMapping("/user/menu2")
    public String regist(HttpServletRequest request, HttpSession session) {
        List<Examine> examines=iExamineService.selectAll();
        List<CarBrands> carBrands=iCarBandsService.selectAll();
        List<CarStyle> carStyles=iCarStyleService.findAll();
        List<Orders> orders=iOrderService.selectOrderAll();
        List<UserDetail> userDetails=iUserDetailService.selectDetailAll();

        request.setAttribute("orderList",orders);
        request.setAttribute("carStyleList",carStyles);
        request.setAttribute("carBrandList",carBrands);
        request.setAttribute("examineList",examines);
        request.setAttribute("userDetailList",userDetails);
        return "menu2";
    }


    @GetMapping("/user/menu1")
    public String menu1(){
        return "menu1";
    }

    @GetMapping("/user/rbac-admin")
    public String rbacadmin(){
        return "rbac-admin";
    }

    @GetMapping("/user/rbac-user-list")
    public String rbacuserlist(){
        return "rbac-user-list";
    }


}
